<?php
namespace app\index\controller;

use app\common\lib\Redis;
use app\common\lib\redis\Predis;
use app\common\lib\Util;
class Login
{
    public function index()
    {
        //获取phone_num code
        $phone_num = intval($_GET['phone_num']);
        $code = intval($_GET['code']);
        if(empty($phone_num) || empty($code)){
            return Util::show(config('code.error'), 'phone or code is null');
        }

        //同步redis code
        try{
            $redis_code = Predis::getInstance()->get(Redis::smsKey($phone_num));
        }catch (\Exception $e){
            return $e->getMessage();
        }
        if($code == $redis_code){
            //记录用户信息到redis里面
            $data = [
                'user' => $phone_num,
                'src_key' => md5(Redis::userKey($phone_num)),
                'time' => time(),
                'is_login' => true
            ];
            Predis::getInstance()->set(Redis::userKey($phone_num), $data);
            return Util::show(config('code.success'), 'ok', $data);
        }else{
            return Util::show(config('code.error'), 'login error');
        }
    }

}







